<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>选择店铺</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/index.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <!--以上为公共js文件-->
</head>
<body>
<div class="zz-header">请选择需要操作的店铺</div>

<div class="zz-store-list">
    <ol>
        <!--<li>-->
        <!--<span class="zz-store">西直门店</span>-->
        <!--<span class="zz-select zz-pathnot zz-path"></span>-->
        <!--</li>-->
    </ol>
</div>
<input class="footer bg zz-footTop" type="button" value="确认">
</body>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript">
    var $store_list = $(".zz-store-list ol");
    var data = '';
    
    function bindHTML() {
        var str = "";
        //var ary = [];
        for (var i = 0; i < data.length; i++) {
            var curData = data[i];
            //if(curData["defultStore"] == 0){
            //	 ary.push(curData["defultStore"]);
            //}
            str += '<li>';
            str += '<span class="zz-store" storeId="' + curData["storeId"] + '" storeShortName="' + curData["storeShortName"] + '" defultStore="' + curData["defultStore"] + '">' + curData["storeShortName"] + '</span>';
            curData["defultStore"] == 0 ? str += '<span class="zz-select zz-pathnot zz-path"></span>' : str += '<span class="zz-select zz-pathnot"></span>';
            str += '</li>';
        }
        $store_list.html(str);
        //if(ary.length>1){
            //$(".zz-select").removeClass("zz-path")
        //}
    }
    //初始化店铺
    $.ajax({
        url: utils.ajaxUrl()+"h5/store/receiver/getStoreByOpenid",
        async: false,
        type: 'get',
        success: function (res) {
        	var res = JSON.parse(res);
        	
            if (res && res.retCode == '0000') {
                data = res["storeList"];
                bindHTML()
            } else {
                new $.modal({
                    content: res.retMsg,//弹框内容
                    showcontent: true,//false为弹出框组件二，true为弹出框组件一
                }).show();
                $(".footer").attr("disabled", "true");
            }
        }
    });
</script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>
<script charset="utf-8" type="text/javascript">

    $(".zz-store-list ol li").click(function () {
        $(this).find(".zz-select").addClass("zz-path");
        $(this).siblings().find(".zz-select").removeClass("zz-path");
    });

    $footer.click(function () {
        var $pathSiblings = $(".zz-path").siblings();
        //传给后台 storeId
        var storeId = $pathSiblings.attr("storeId");
        var storeShortName = $pathSiblings.attr("storeShortName");
        var defultStore = $pathSiblings.attr("defultStore");
        if(defultStore ==0){
        	new $.modal({
                content: "当前是默认店铺，请重新选择！",//弹框内容
                showcontent: true,//false为弹出框组件二，true为弹出框组件一
            }).show($footer);
            return false;
        };
        
        new $.modal({
            content: "加载中",
            animation: true//调用动画
        }).show();
        
        //$footer.attr("disabled", "true");
        $.ajax({
            url: utils.ajaxUrl()+"h5/store/receiver/updateStore",
            async: false,
            data: {
                storeId: storeId
            },
            type: 'get',
            success: function (res) {
            	var res = JSON.parse(res);
        		//console.log(res);
        		//alert(res.retMsg);
                if (res && res.retCode == '0000') {
                	
                	new $.modal({
            			animation: true,//调用动画
        			}).hide(0);
        			
                	new $.modal({
                        content: "默认店铺修改成功",//弹框内容
                        showcontent: true,//false为弹出框组件二，true为弹出框组件一
                    }).show($footer,2000);
                    
                    setTimeout(function(){
                    	window.location.href = "storeMsg.html";
                    	//$footer.removeAttr("disabled");
                    },2000);
                } else {
                	new $.modal({
            			animation: true,//调用动画
        			}).hide(0);
                    new $.modal({
                        content: res.retMsg,//弹框内容
                        showcontent: true,//false为弹出框组件二，true为弹出框组件一
                    }).show($footer);
                }
            }
        });
    })

</script>
</html>